package com.lovo;

import com.lovo.hb.dao.ITeacherDao;
import com.lovo.hb.entity.StudentEntity;
import com.lovo.hb.entity.TeacherEntity;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

@SpringBootTest(classes = com.lovo.HibernateMain.class)
public class OneToMany {
    @Autowired
    private ITeacherDao teacherDao;

    @Test
    @Transactional
    public void oneToManyT(){
    TeacherEntity t= teacherDao.findById(1l).get();
        System.out.println(t.getTeacherName());
    Set<StudentEntity> sets=t.getStus();
        for (StudentEntity stu:sets) {
            System.out.println(stu.getStuName());
        }
    }
}
